﻿namespace BloggerBackup
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    [Designer(typeof(TextboxCueSmartTagDesigner))]
    public class TextboxCue : TextBox
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        private string _textPrompt;
        private bool _usePrompt;
        private IContainer components;
        private const string DEFAULTPROMPT = "Enter a text prompt";

        public TextboxCue()
        {
            List<WeakReference> list = __ENCList;
            lock (list)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this._textPrompt = "Enter a text prompt";
        }

        [DebuggerNonUserCode]
        protected override void Dispose(bool disposing)
        {
            if (((disposing && (this.components != null)) ? 1 : 0) != 0)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.components = new Container();
        }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            if (this.UsePrompt)
            {
                this.UsePrompt = false;
                this.Text = string.Empty;
            }
        }

        protected override void OnLostFocus(EventArgs e)
        {
            if ((((this.TextLength == 0) || (this.Text == this.TextPrompt)) ? 1 : 0) != 0)
            {
                this.UsePrompt = true;
                this.Text = this.TextPrompt;
            }
            base.OnLostFocus(e);
        }

        protected override void OnParentChanged(EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Text))
            {
                this.UsePrompt = true;
                this.Text = this.TextPrompt;
            }
            base.OnParentChanged(e);
        }

        public override string Text
        {
            get
            {
                if (this.UsePrompt)
                {
                    return string.Empty;
                }
                return base.Text;
            }
            set
            {
                if ((((this.UsePrompt && !string.IsNullOrEmpty(value)) && (value != this.TextPrompt)) ? 1 : 0) != 0)
                {
                    this.UsePrompt = false;
                }
                if ((((string.IsNullOrEmpty(value) && !this.Focused) && !string.IsNullOrEmpty(this.TextPrompt)) ? 1 : 0) != 0)
                {
                    this.UsePrompt = true;
                    base.Text = this.TextPrompt;
                }
                else
                {
                    base.Text = value;
                }
            }
        }

        [Category("Data"), DefaultValue("Enter a text prompt")]
        public string TextPrompt
        {
            get
            {
                return this._textPrompt;
            }
            set
            {
                this._textPrompt = value;
                if (((this.UsePrompt && !string.IsNullOrEmpty(this._textPrompt)) ? 1 : 0) != 0)
                {
                    this.Text = value;
                }
            }
        }

        private bool UsePrompt
        {
            get
            {
                return this._usePrompt;
            }
            set
            {
                this._usePrompt = value;
                if (this._usePrompt)
                {
                    this.Font = new Font(this.Font.Name, this.Font.Size, FontStyle.Italic);
                    this.ForeColor = Color.Gray;
                }
                else
                {
                    this.Font = new Font(this.Font.Name, this.Font.Size, FontStyle.Regular);
                    this.ForeColor = Color.Black;
                }
            }
        }
    }
}

